#!/bin/bash

DOCKER_NAME="qascript-ncs-api-test"
#nsf_api_test begin need change qingzhou_test.properties
sed -i 's/SceneType=true/SceneType=false/'  /data/ncs-qatest/config/qingzhou_test.properties

if [ -d {{ data_dir }}/ncs-qatest/ncs/logs ];then
    mv {{ data_dir }}/ncs-qatest/ncs/logs {{ data_dir }}/ncs-qatest/ncs/logs-`date +%F-%H%M%S`
fi

if [ -d {{ data_dir }}/ncs-qatest/ncs/test-output ];then
    mv {{ data_dir }}/ncs-qatest/ncs/test-output  {{ data_dir }}/ncs-qatest/ncs/test-output-`date +%F-%H%M%S`
fi

ret=$(docker ps -a |grep "$DOCKER_NAME"|grep -v grep|wc -l)
if [ $ret -gt 0 ];then
    docker stop $DOCKER_NAME &>/dev/null
    docker rm $DOCKER_NAME
fi

# 获取dns的clusterip地址，在机器上测试时使用
# 轻舟名称: coredns
# rancher部署k8s是: kube-dns
CLUSTER_DNS_SVC_IP=$(kubectl  -n kube-system get svc |grep dns|awk '{print $3}'|sed 's/ //g')

docker run --net host --dns $CLUSTER_DNS_SVC_IP --name $DOCKER_NAME \
-v {{ data_dir }}/ncs-qatest/config:/test/config \
-v {{ data_dir }}/ncs-qatest/ncs/skiffncs_api_test.xml:/test/ncs_api_test.xml \
-v {{ data_dir }}/ncs-qatest/ncs/logs:/test/logs \
-v {{ data_dir }}/ncs-qatest/ncs/test-output:/test/test-output  \
-v /var/run/docker.sock:/var/run/docker.sock \
-d {{ image_registry.addr }}/{{ image_registry.project }}/{{ image.qascript_ncs_api_test_image }}
